﻿@{
    var _newpage = Request["_newpage"] == "true" || ViewBag._newpage == "true";
    //class ="@(ViewContext.RouteData.Values["action"].ToString() == item.A && ViewContext.RouteData.Values["controller"].ToString() == item.C ? "selected" : "")"
    var ActiveMenuName = ViewContext.RouteData.Values["controller"].ToString() + "-" + ViewContext.RouteData.Values["action"].ToString();
    var ActiveMenuGroupName = Request["_MG"];
}
@helper RenderMenu(dynamic[] items, string classname = "", int level = 0, string cm = null)
    {
    <ul class="menu @classname menu-@(level == 0 ? "main" : "sub") menu-lv@(level)">
        @foreach (dynamic item in items)
        {
            if (item.T == "-")
            {
            <li style="color: White; vertical-align: middle; margin: 0 0 .3em 0;"><span style="display: block;
                height: 2em; width: 0px; margin: 0 1em 0 1em; border-right: 1px solid white;"></span>
            </li>
            }
            else
            {
                if ("" != item.A && !((string)item.A).EndsWith("/"))
                {
                    var rvs = item.R;
            <li data-menukey="@((string)item.C + "-" + (string)item.A)" >@Html.ActionLink((string)item.T, (string)item.A, (string)item.C, (object)rvs, null)</li>
                }
                else
                {
            <li data-menukey="@(item.A)" class="sml"><a href="#@item.A">@(item.T)</a>
                @RenderMenu((dynamic[])item.S, classname, level + 1, (string)item.A) </li>
                }
            }
        }
    </ul>
}
<style type="text/css">
    ul.menu-nav
    {
        float: left;
    }
    
    ul.menu-ext
    {
        float: right;
    }
    ul.menu-sub
    {
        position: absolute;
        z-index: 999; /*top: -999px;*/
        visibility: hidden;
        text-align: left;
        border: 1px solid #535353;
        background: #fff;
        -moz-box-shadow: -1px 1px 1px rgba(0,0,0,.2);
        -webkit-box-shadow: 0 2px 4px rgba(0,0,0,.2);
        box-shadow: 0 2px 4px rgba(0,0,0,.2);
        list-style: none;
        margin: 0;
        padding: 0;
        margin-top: -4px;
        line-height: 2em;
    }
    ul.menu-sub a
    {
        min-width: 8em;
        display: block;
        color: #333333;
        text-decoration: none !important;
        padding: 0 1em 0 1em;
        border: 0.2em solid transparent;
    }
    ul.menu-sub a:hover
    {
        background-color: #f17733;
        color: white;
    }
    ul.menu-sub li.selected a
    {
        background-color: #f17733;
        color: white;
    }
    
    .menu-pop ul.menu-sub
    {
        /*top: 29px;*/
        visibility: visible;
        right: auto; /*left: 0px;*/
    }
    
    .menu-pop > a
    {
        border: 1px solid #535353 !important;
        border-bottom: 0px solid #535353 !important;
        color: #535353 !important;
        text-decoration: none;
        background-color: White;
        box-shadow: 2px 2px 2px #535353;
    }
</style>
<nav  class="menu"  style="@(_newpage ? "display:none;" : "");">
    @{
        var menus = new Dictionary<string, dynamic[]>();
        menus.Add("Admin", new dynamic[]{
            new{ T = "常规随访查询", A = "QizSessionMgr", C = "SystemMgr", R = new{} }
            ,new{ T = "短信随访查询", A = "QizSmsSessionList", C = "SystemMgr", R = new{} }
            ,new{ T = "-"  }
            ,new{ T = "系统短信查询", A = "ManageSmsList", C = "SystemMgr", R = new{IsView=true} }
            ,new{ T = "接收短信查询", A = "ReceivedSms", C = "SystemMgr", R = new{IsView=true} }
            ,new{ T = "-"  }
            ,new{ T = "医生管理", A = "DoctorMgr", C = "SystemMgr", R = new{} }
            ,new{ T = "常规随访管理", A = "HospAndDepartMgr", C = "SystemMgr", R = new{} }
            ,new{ T = "选择定义", A = "EnumMgr", C = "SystemMgr", R = new{} }
            ,new{ T = "随访项定义", A = "SuiFangMgr", C = "SystemMgr", R = new{} }
            });

        menus.Add("Doctor", new dynamic[]{
            new{ T = "常规随访查询", A = "QizSessionList", C = "Doctor", R = new{IsView=true} }
            ,new{ T = "短信随访查询", A = "QizSmsSessionList", C = "Doctor", R = new{} }
            ,new{ T = "-"  }
            ,new{ T = "患者信息管理", A = "RecuperMgr", C = "Doctor", R = new{} }
            ,new{ T = "随访对象管理", A = "SubjectRecuperMgr", C = "Doctor", R = new{} }
            ,new{ T = "短信随访管理", A = "SmsQuizMgr", C = "Doctor", R = new{} }            
            ,new{ T = "随访档案查询", A = "RecuperReport", C = "Doctor", R = new{} }
            ,new{ T = "-"  }
            ,new { T = "短信平台管理",A="DuanXinPingTai/", S=new dynamic[]{
                new{ T = "短信留言", A = "SentSmsEdit", C = "Doctor", R = new{_MG="DuanXinPingTai/",IsView=true} }
                ,new{ T = "发送短信查询", A = "SentSms", C = "Doctor", R = new{_MG="DuanXinPingTai/"} }
                //,new{ T = "接收短信查询", A = "RecuperReport", C = "Doctor", R = new{_MG="DuanXinPingTai/"} }
             } }
            ,new{T="系统管理",A="XiTongGuanLi/",S=new dynamic[]{
                 new{ T = "填报质量定制", A = "TagTemplateMgr", C = "Doctor", R = new{_MG="XiTongGuanLi/",Key="TianBaoZhiLiang"} }
                ,new{ T = "随访类型定制", A = "TagTemplateMgr", C = "Doctor", R = new{_MG="XiTongGuanLi/",Key="SuiFangLeiXing",IsView=true} }
                ,new{ T = "常用短信定制", A = "SmsTemplateMgr", C = "Doctor", R = new{_MG="XiTongGuanLi/"} }                
                //,new{ T = "患者扩展信息定制", A = "RecuperAttachInfoMgrXXX", C = "Doctor", R = new{_MG="XiTongGuanLi/",Target="User"} }
                //,new{ T = "住院扩展信息定制", A = "RecuperAttachInfoMgr", C = "Doctor", R = new{_MG="XiTongGuanLi/",Target="Recuper"} }
                ,new{ T = "扩展信息定制", A = "RecuperAttachInfoMgr", C = "Doctor", R = new{_MG="XiTongGuanLi/",Target="Recuper"} }
            }}
            }
       );

        menus.Add("Recuper", new dynamic[]{
            new{ T = "随访填报", A = "MySfdList", C = "Recuper", R = new{} }
            ,new{ T = "医生留言", A = "MyQizCommList", C = "Recuper", R = new{} }
            ,new{ T = "-"  }            
            ,new{ T = "随访档案查询", A = "RecuperReport", C = "Recuper", R = new{} }
            ,new{ T = "常规随访查询", A = "QizSessionList", C = "Recuper", R = new{IsView=true} }
            ,new{ T = "短信随访查询", A = "QizSmsSessionList", C = "Recuper", R = new{} }
            ,new{ T = "系统短信查询", A = "SentSms", C = "Recuper", R = new{} }
            ,new{ T = "-"  }            
            ,new{ T = "数据分析", A = "QizItemValueAnalysis", C = "Recuper", R = new{} }

            }
       );

        menus.Add("Recuper_Ext", new dynamic[]{
            new{ T = "健康大事记", A = "UserMemoList", C = "Recuper", R = new{IsView=true} }
       });
        menus.Add("Doctor_Ext", new dynamic[]{
            new{ T = "健康备忘录", A = "UserMemoList", C = "Doctor", R = new{IsView=true} }
       });
        var roles = new string[] { "Admin", "Doctor", "Recuper" };

        bool isEngineer = User.IsInRole("Engineer");
    }

    @foreach (var role in roles)
    {
        if (isEngineer || User.IsInRole(role))
        {
            @RenderMenu(menus[role], "menu-nav")
            if (menus.ContainsKey(role + "_Ext"))
            {
                @RenderMenu(menus[role + "_Ext"], "menu-ext")
            }
        }
    }
</nav>
<script type="text/javascript">
    $(function () {
        $("li[data-menukey='@(ActiveMenuName)']").addClass("selected");
        $("li[data-menukey='@(string.IsNullOrEmpty(ActiveMenuGroupName) ? "NULL" : ActiveMenuGroupName)']").addClass("selected");
        $("li.sml").click(function (e) {
            //e.preventDefault();
            var isthispop = $(this).hasClass("menu-pop");
            $("li.sml").removeClass("menu-pop");
            if (!isthispop) $(this).addClass("menu-pop");
            //$(this).toggleClass("menu-pop");

            e.stopImmediatePropagation();
            var m = this;
            $(document).one("click", function (e) {
                $(m).removeClass("menu-pop");
            });
        });
    });
</script>
